package org.loofer.transferlive;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

import org.loofer.transferlive.adapter.MyViewPagerAdapter;
import org.loofer.transferlive.fragment.FirstFragment;
import org.loofer.transferlive.fragment.SecondFragment;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {


    private ViewPager viewPager;
    private List<Fragment> fragmentList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();
    }


    private void initView (){
        viewPager=(ViewPager) findViewById(R.id.viewPager);
        fragmentList = new ArrayList<>();
        FirstFragment first=new FirstFragment();
        SecondFragment second=new SecondFragment();
        fragmentList.add(first);
        fragmentList.add(second);

        //给ViewPager设置适配器
        viewPager.setAdapter(new MyViewPagerAdapter(getSupportFragmentManager(), fragmentList));
        viewPager.setCurrentItem(1);//设置当前显示标签页为第一页
    }

}
